package edu.stu.cs.software.family.producer.web.spring.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import edu.stu.cs.software.family.base.web.spring.controller.GenericController;
import edu.stu.cs.software.family.producer.domain.Producer;
import edu.stu.cs.software.family.producer.service.ProducerManager;

@Controller
@RequestMapping("/producer")
public class ProducerController extends GenericController<Producer, Long, ProducerManager> {

	ProducerManager producerManager;
	/*
	 * String
	 * return 
	 */
	@RequestMapping("/index")
	public String index() {
		return "producer/index";
	}
	
	@Autowired
	public void setUserManager(ProducerManager producerManager) {
		this.producerManager = producerManager;
		this.manager = this.producerManager;
	}
	@PostMapping("/login")
	public String dologin(@RequestParam String userName,@RequestParam String password)
	{
		
		Producer producer = this.producerManager.findByProducerName(userName);
		if (producer == null) {
            return "error";
        }
        if (!password.equals(((Producer) producer).getPassword())) {
            return "error";
        }
        return "success";
	}
}
